<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2017/9/17
 * Time: 15:41
 */

namespace Home\Controller;


use Think\Controller;

class CourseController extends Controller
{
    /**
     * 课程列表
     */
    public function index(){
        $courseList = D('courses')->select();
        if ($courseList){
            foreach ( $courseList as $key=>$value ){
                $courseList[$key]['startime'] = explode(' ',$value['startime'])[0];
                $courseList[$key]['endtime'] = explode(' ',$value['endtime'])[0];
                $courseList[$key]['type'] = M('class')->where(array('id'=>$value['type']))->getField('name');
            }
        }

        $this->assign('courseList',$courseList);
        $this->assign('discount',M('discount')->find(1));
        $this->display('Index/curriculum');
    }

    /**
     * 课程详情
     */
    public function courseDetail(){
        $cid = I('get.id');
        $courseInfo = D('courses')->where(array('id'=>$cid))->find();
        $courseInfo['value'] = html_entity_decode($courseInfo['value']);
        $this->assign('courseInfo',$courseInfo);
        $this->display('Index/curriculum_details');
    }

    /**
     * 课程回顾列表
     */
    public function reviews(){
        $reviewsList = D('course_review')->select();
        if ($reviewsList){
            foreach ( $reviewsList as $key=>$value ){
                $reviewsList[$key]['createtime'] = substr(date('Y-m-d',strtotime($value['createtime'])),2);
                $reviewsList[$key]['value'] = substr_replace(strip_tags(html_entity_decode($value['value'])),"......",50);
            }
        }
        $this->assign('reviewsList',$reviewsList);
        $this->display('Index/review');
    }

    /**
     * 课程回顾详情
     */
    public function reviewsDetail(){
        $rid = I('get.id');
        $courseInfo = D('course_review')->where(array('id'=>$rid))->find();
        $courseInfo['value'] = html_entity_decode($courseInfo['value']);
        $this->assign('reviewInfo',$courseInfo);
        $this->display('Index/review_details');
    }
}